<?php
if ($_SESSION['wiz_skad']=='') $_SESSION['wiz_skad']='wiz_wyw';


if ($_POST['sz_lek']) $_SESSION['sz_lek']=$_POST['sz_lek'];
if ($_GET['wiz_szablon']){
$sql="select tekst from sl_szablony where id = ".$_GET['wiz_szablon'];

$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
if ($_SESSION['wiz_skad']=='wiz_badanie') $_SESSION['wiz_badanie_opis']=$_SESSION['wiz_badanie_opis'].$row[0];
if ($_SESSION['wiz_skad']=='wiz_wyw') $_SESSION['wiz_wyw_opis']=$_SESSION['wiz_wyw_opis'].$row[0];
if ($_SESSION['wiz_skad']=='wiz_zalecenia') $_SESSION['wiz_zalecenia_opis']=$_SESSION['wiz_zalecenia_opis'].$row[0];  
}
}

echo '<form action="index.php" method=POST>';
echo '<table align="center" width="90%" border=0>';
echo '<tr><td colspan=3 align="center"><input type=submit value="Poprzednie wizyty" name="wiz_popw" class="butt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Wywiad" name="wiz_wyw" class="butt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Badanie" name="wiz_badanie" class="butt4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Wyniki badan" name="wiz_wyniki_badan"
class="butt4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Zalecenia" name="wiz_zalecenia" class="butt4">';
#echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Leki" name="wiz_leki" class="butt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Zlecenia" name="wiz_zlecenia" class="butt4">';
echo '</td></tr>';



if ($_POST['wiz_wyw'] ||$_SESSION['wiz_skad']=='wiz_wyw'){
    echo '<tr><td>Wywiad</td><td align="center"><textarea name="wiz_wyw_opis" rows=20 cols=80>'.$_SESSION['wiz_wyw_opis'].'</textarea></td><td><input type=submit value="Szablon" name="wiz_szablon" class="butt"></td></tr>';
}

if ($_POST['wiz_popw'] ||$_SESSION['wiz_skad']=='wiz_popw'){
    $sqlr="select wizyty.id from wizyty, wizyty_inf where wizyty.id = wizyty_inf.id_wiz and wizyty.id_pac = ".$_SESSION['wyb_pac_id']." order by wizyty.data desc";
	$result2=mysql_query($sqlr);
while($row2 = mysql_fetch_array($result2))
{

$sql3="select DATE_FORMAT(wizyty.data, '%Y-%m-%d %k:%i') as czas, pac.pac_imie, pac.pac_nazwisko, wizyty_inf.wywiad, wizyty_inf.badanie, wizyty_inf.zalecenia from wizyty_inf, wizyty, pac 
where wizyty.id=wizyty_inf.id_wiz
and
wizyty.id_pac=pac.id
and 
wizyty_inf.id_wiz=".$row2['id'];
#echo $sql;
$result3=mysql_query($sql3);
$row3 = mysql_fetch_array($result3);
echo '<tr><td>';
echo '<table align="center" class="linia" width="80%"><tr class="linia"><td class="linia">';
echo 'Pacjent: '.$row3[2].' '.$row3[1];
echo '<br>Data wizyty: '.$row3[0];
echo '</td></tr>';

echo '<tr class="linia"><td class="linia">';
echo 'Wywiad:';
echo '<br>'.$row3[3];
echo '</td></tr>';

echo '<tr class="linia"><td class="linia">';
echo 'Badanie:';
echo '<br>'.$row3[4];
echo '</td></tr>';

echo '<tr class="linia"><td class="linia">';
echo 'Zalecenia:';
echo '<br>'.$row3[5];
echo '</td></tr>';

echo '<tr class="linia"><td class="linia">';
echo '<a href="./pdf/wydr_wiz.php?wiz='.$row2['id'].'" target="_blank">Wydruk karty informacyjnej</a>';

echo '</td></tr>';


echo '</table>';
echo '</td></tr>';
#echo $row[1];


}	
}

if ($_POST['wiz_badanie']||$_SESSION['wiz_skad']=='wiz_badanie'){
    echo '<tr><td>Badanie</td><td align="center"><textarea name="wiz_badanie_opis" rows=20 cols=80>'.$_SESSION['wiz_badanie_opis'].'</textarea></td><td><input type=submit value="Szablon" name="wiz_szablon" class="butt"></td></tr>';
}

if ($_POST['wiz_zalecenia']||$_SESSION['wiz_skad']=='wiz_zalecenia'){
    echo '<tr><td>Zalecenia</td><td align="center"><textarea name="wiz_zalecenia_opis" rows=20 cols=80>'.$_SESSION['wiz_zalecenia_opis'].'</textarea></td><td><input type=submit value="Szablon" name="wiz_szablon" class="butt"></td></tr>';
}

if ($_POST['wiz_zlecenia']||$_SESSION['wiz_skad']=='wiz_zlecenia'){
    echo '<tr><td colspan=2>Zlecenia</td></tr>';
	$sql="select * from sl_zlecenia";
        $result=mysql_query($sql);
        while($row = @mysql_fetch_array($result))
        {
            echo '<tr><td class="linia"><input type="checkbox" class="butt" name="wiz_zlec_det['.$row['id'].']" ';
			if ($_SESSION['wiz_zlec_det'][$row['id']]=='on') echo 'checked';
			echo '>'.$row['nazwa'].'</td></tr>';
        }
	echo '';
}


if ($_POST['wiz_wyniki_badan']||$_SESSION['wiz_skad']=='wiz_wyniki_badan'){
    echo '<tr><td>Wyniki badań</td><td align="left">';
	$sql="select * from sl_badania order by nazwa";
        $result=mysql_query($sql);
        $rodz_bad[10000]='Wybierz ..';
		while($row = mysql_fetch_array($result))
        {
            $rodz_bad[$row[0]]=$row[1];
        }
		form_auto_submit_2n  ('rodz_bad', $rodz_bad,$_SESSION['rodz_bad']);
		echo '<input type=submit value="Wybierz" name="wyw" class="butt">';
		if ($_SESSION['rodz_bad']<>'' || $_SESSION['rodz_bad']<>'10000'){
		echo '<table>';
		$sql="select * from sl_badania_det where id_bad = ".$_SESSION['rodz_bad'];
        $result=mysql_query($sql);
        while($row = @mysql_fetch_array($result))
        {
            echo '<tr class="linia"><td class="linia">'.$row['nazwa'].'</td><td><input type=text size=15 name="bad_wyn_jedn['.$row[1].']"  value="'.$_SESSION['bad_wyn_jedn'][$_SESSION['rodz_bad']][$row[1]].'" class="butt2"></td><td class="linia">'.$row['jedn'].'</td></tr>';
        }
		echo '</table>';
		}
	echo '</td></tr>';
}


if ($_POST['wiz_leki']||$_SESSION['wiz_skad']=='wiz_leki'){
    if ($_SESSION['wyb_lek_id']){
        $wyb_id_lek=implode(", ", $_SESSION['wyb_lek_id']);
        $sql="select * from sl_bloz where id in (".$wyb_id_lek.")";
        $result=mysql_query($sql);
        while($row = mysql_fetch_array($result))
        {
            echo '<tr class="linia"><td class="linia" colspan=2>'.$row[1].' - '.$row[2].'</td></tr>';
        }
    
    }    
echo '<tr class="linia"><td class="linia">Nazwa leku</td><td class="linia"><input type=text size=80 name="sz_lek" value="'.$_SESSION['sz_lek'].'" class="butt2"></td></tr>';
echo '<tr class="linia"><td class="linia" colspan=2 align="center"><input type="submit" class="butt" name="sz_lek_b" value="Szukaj"></td></tr>';
if ($_POST['sz_lek']){
$sql="select * from sl_bloz where nazwa like '%".$_POST['sz_lek']."%'";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo '<tr class="linia"><td class="linia" align="center"><input type="submit" class="butt" name="wyb_lek_b['.$row[0].']" value="Wybierz"></td><td class="linia">'.$row[1].'&nbsp;&nbsp;&nbsp;&nbsp;'.$row[2].'&nbsp;&nbsp;&nbsp;&nbsp;'.$row[3].'</td></tr>';}
}
}

echo '<tr><td colspan=3 align="center"><input type=submit value="Anuluj" name="wiz_anuluj" class="butt4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Zapisz" name="wiz_zapisz" class="butt"></td></tr>';


echo '</table>';
echo '</form>';
?>